package com.edu.rpc.controller;

import com.edu.rpc.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/weather")
public class WeatherController {
    @Autowired
    private WeatherService weatherService;

    // 获取城市接口
    @GetMapping("/city")
    @PreAuthorize("hasAuthority('file_read')")
    public Mono<String> getCities() {
        return weatherService.getCities();
    }

    /**
     * 根据城市名称查询天气
     */
    @GetMapping("/city/{cityName}")
    public Mono<String> getWeatherByCity(@PathVariable("cityName") String city) {
        return weatherService.getWeatherByCityName(city);
    }

    /**
     * 根据城市Id获取天气
     */
    @GetMapping("/cityId/{cityId}")
    public Mono<String> getWeatherByCityId(@PathVariable("cityId") String cityId) {
        return weatherService.getWeatherByCityId(cityId);
    }
}
